<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>推理模式调试工具</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .debug-container {
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            margin-bottom: 20px;
        }
        .status {
            padding: 10px;
            border-radius: 4px;
            margin: 10px 0;
        }
        .success { background-color: #d4edda; color: #155724; }
        .error { background-color: #f8d7da; color: #721c24; }
        .info { background-color: #d1ecf1; color: #0c5460; }
        button {
            background-color: #007bff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            margin: 5px;
        }
        button:hover {
            background-color: #0056b3;
        }
        .url-display {
            background-color: #f8f9fa;
            padding: 10px;
            border-radius: 4px;
            font-family: monospace;
            word-break: break-all;
        }
    </style>
</head>
<body>
    <h1>推理模式URL参数调试工具</h1>
    
    <div class="debug-container">
        <h2>当前环境信息</h2>
        <div id="env-info"></div>
    </div>
    
    <div class="debug-container">
        <h2>URL参数测试</h2>
        <button onclick="testReasoningTrue()">设置 reasoning=true</button>
        <button onclick="testReasoningFalse()">设置 reasoning=false</button>
        <button onclick="clearParams()">清除所有参数</button>
        <div id="url-status"></div>
    </div>
    
    <div class="debug-container">
        <h2>当前URL</h2>
        <div id="current-url" class="url-display"></div>
    </div>
    
    <div class="debug-container">
        <h2>URL参数解析</h2>
        <div id="params-display"></div>
    </div>
    
    <div class="debug-container">
        <h2>浏览器兼容性检查</h2>
        <div id="browser-check"></div>
    </div>

    <script>
        function updateDisplay() {
            // 显示当前URL
            document.getElementById('current-url').textContent = window.location.href;
            
            // 解析URL参数
            const urlParams = new URLSearchParams(window.location.search);
            const paramsDiv = document.getElementById('params-display');
            
            if (urlParams.toString()) {
                let paramsHtml = '<h4>检测到的参数:</h4>';
                for (const [key, value] of urlParams) {
                    paramsHtml += `<div class="status info"><strong>${key}:</strong> ${value}</div>`;
                }
                paramsDiv.innerHTML = paramsHtml;
            } else {
                paramsDiv.innerHTML = '<div class="status info">没有检测到URL参数</div>';
            }
            
            // 检查reasoning参数
            const reasoning = urlParams.get('reasoning');
            const statusDiv = document.getElementById('url-status');
            
            if (reasoning === 'true') {
                statusDiv.innerHTML = '<div class="status success">✓ reasoning参数正确设置为true</div>';
            } else if (reasoning === 'false') {
                statusDiv.innerHTML = '<div class="status info">reasoning参数设置为false</div>';
            } else if (reasoning === null) {
                statusDiv.innerHTML = '<div class="status info">未检测到reasoning参数</div>';
            } else {
                statusDiv.innerHTML = `<div class="status error">⚠ reasoning参数值异常: ${reasoning}</div>`;
            }
        }
        
        function testReasoningTrue() {
            const url = new URL(window.location);
            url.searchParams.set('reasoning', 'true');
            window.history.pushState({}, '', url);
            updateDisplay();
        }
        
        function testReasoningFalse() {
            const url = new URL(window.location);
            url.searchParams.set('reasoning', 'false');
            window.history.pushState({}, '', url);
            updateDisplay();
        }
        
        function clearParams() {
            const url = new URL(window.location);
            url.search = '';
            window.history.pushState({}, '', url);
            updateDisplay();
        }
        
        function checkEnvironment() {
            const envDiv = document.getElementById('env-info');
            const isLocal = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
            const isProduction = window.location.hostname.includes('10.10.10.125');
            
            let envHtml = `
                <div class="status info"><strong>主机名:</strong> ${window.location.hostname}</div>
                <div class="status info"><strong>端口:</strong> ${window.location.port}</div>
                <div class="status info"><strong>协议:</strong> ${window.location.protocol}</div>
                <div class="status ${isLocal ? 'success' : 'info'}"><strong>环境:</strong> ${isLocal ? '开发环境' : (isProduction ? '生产环境' : '未知环境')}</div>
            `;
            
            envDiv.innerHTML = envHtml;
        }
        
        function checkBrowserCompatibility() {
            const browserDiv = document.getElementById('browser-check');
            let checks = [];
            
            // 检查URLSearchParams支持
            if (typeof URLSearchParams !== 'undefined') {
                checks.push('<div class="status success">✓ URLSearchParams API 支持</div>');
            } else {
                checks.push('<div class="status error">✗ URLSearchParams API 不支持</div>');
            }
            
            // 检查History API支持
            if (window.history && window.history.pushState) {
                checks.push('<div class="status success">✓ History API 支持</div>');
            } else {
                checks.push('<div class="status error">✗ History API 不支持</div>');
            }
            
            // 检查URL构造函数支持
            try {
                new URL(window.location.href);
                checks.push('<div class="status success">✓ URL 构造函数支持</div>');
            } catch (e) {
                checks.push('<div class="status error">✗ URL 构造函数不支持</div>');
            }
            
            browserDiv.innerHTML = checks.join('');
        }
        
        // 页面加载时初始化
        window.addEventListener('load', function() {
            updateDisplay();
            checkEnvironment();
            checkBrowserCompatibility();
        });
        
        // 监听URL变化
        window.addEventListener('popstate', updateDisplay);
    </script>
</body>
</html>